package com.seafood.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;

/**
 * 购物车实体类
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "shopping_cart", 
       uniqueConstraints = @UniqueConstraint(columnNames = {"user_id", "product_id"}))
public class ShoppingCart extends BaseEntity {
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    private User user;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", nullable = false)
    private Product product;
    
    @NotNull(message = "数量不能为空")
    @Positive(message = "数量必须大于0")
    @Column(nullable = false)
    private Integer quantity;
}